Skip to content

add option to generate test coverage report without codecov#207

Merged
Cadair merged 1 commit intoOpenAstronomy:mainfrom
zacharyburnett:tox/coverage_github_actions
Feb 25, 2026
Merged

add option to generate test coverage report without codecov#207
Cadair merged 1 commit intoOpenAstronomy:mainfrom
zacharyburnett:tox/coverage_github_actions

Conversation

@zacharyburnett
Copy link
Contributor

@zacharyburnett zacharyburnett commented Jun 9, 2024

using the guide here: https://hynek.me/articles/ditch-codecov-python/

This does not create coverage diffs or report to PRs, just creates a markdown summary table

closes #189

EDIT: here's what the summary table looks like:
image

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 8a31636 to fba02a5 Compare June 9, 2024 17:06
@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

I tried this out on sunpy and it seems to explode. sunpy/sunpy#7668

@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

It seems that it's not picking up the coverage.xml to upload here: https://github.com/sunpy/sunpy/actions/runs/9445798095/job/26014155532?pr=7668#step:14:16 🤔

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for taking a swing at this!

- run: python -Im pip install --upgrade coverage[toml]
- run: python -Im coverage combine
- run: python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to add the ability to fail this job based on either total coverage % or diff coverage %.

@pllim
Copy link
Contributor

pllim commented Jun 10, 2024

tl;dr -- this does not generate patch coverage, right?

@Cadair
Copy link
Member

Cadair commented Jun 10, 2024

Not yet, but I found a way to make it.

@zacharyburnett
Copy link
Contributor Author

tl;dr -- this does not generate patch coverage, right?

Not yet, but I found a way to make it.

For patch coverage we'd need to store the coverage from main somewhere, to compare it to; some people I've seen online have done that by storing it in a hidden page in the repository's wiki, reading and writing it with a github token with ${{ secrets.GITHUB_TOKEN }}

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 325b539 to 156160e Compare June 10, 2024 17:59
@pllim
Copy link
Contributor

pllim commented Jun 11, 2024

@zacharyburnett
Copy link
Contributor Author

I am trying this out too at spacetelescope/acstools#205 and it still crashes:

https://github.com/spacetelescope/acstools/actions/runs/9463279566/job/26068438067?pr=205

oh whoops, I fixed the artifact issue:
image
but didn't pass any filenames to coverage combine 😅
image

@pllim

This comment was marked as resolved.

@pllim

This comment was marked as outdated.

@pllim

This comment was marked as outdated.

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

Even when CI passes, it failed with the same error.

Coverage XML written to file coverage.xml

mv: cannot stat '.coverage': No such file or directory

@pllim pllim mentioned this pull request Jun 12, 2024
@zacharyburnett
Copy link
Contributor Author

Even when CI passes, it failed with the same error.

Coverage XML written to file coverage.xml

mv: cannot stat '.coverage': No such file or directory

it should be uploading / downloading the .coverage database, to be able to combine multiple machine types, so if that's not present then something is messed up

@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Jun 12, 2024

it looks like --cov-report=xml is what's creating the coverage.xml; however, it should still be creating a .coverage database file... I'll so some local testing to see what files it spits out
https://github.com/spacetelescope/acstools/actions/runs/9463279566/job/26118526244#step:10:105

pytest --pyargs acstools --cov-report=xml --cov=acstools /home/runner/work/acstools/acstools/doc --cov --remote-data -v

@zacharyburnett
Copy link
Contributor Author

running pytest --pyargs acstools --cov-report=xml --cov=acstools --cov --remote-data -v locally does appear to create the .coverage file:

❯ ls -a
.							CITATION.md
..							CODE_OF_CONDUCT.md
.bandit.yaml						LICENSE.md
.coverage						MANIFEST.in
.coverage.urelialia2022.local.stsci.edu.35749.XCMKciAx	README.rst
.git							__pycache__
.github							acstools
.gitignore						acstools.egg-info
.mypy_cache						conftest.py
.pytest_cache						coverage.xml
.readthedocs.yaml					doc
.tmp							pyproject.toml
.tox							tox.ini

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

What is the difference between .coverage and coverage.xml?

@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Jun 12, 2024

What is the difference between .coverage and coverage.xml?

I'm not intimately familiar with it, but as far as I know .coverage is a SQLite database file with support for parallel-mode (storing coverage for multiple machine configurations / runs) while coverage.xml is report-focused and so is expected to only contain results from a single run.

We could use coverage.xml, but then we'd need to have a summary table of coverage for each and every run, instead of a single table collating all runs

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

Tried to debug at #209 but no luck. I see the coverage ran but the the upload failed: https://github.com/spacetelescope/acstools/actions/runs/9483014271/job/26134042811?pr=205

@zacharyburnett
Copy link
Contributor Author

Tried to debug at #209 but no luck. I see the coverage ran but the the upload failed: https://github.com/spacetelescope/acstools/actions/runs/9483014271/job/26134042811?pr=205

could you also add -a to the ls?

@pllim
Copy link
Contributor

pllim commented Jun 12, 2024

@neutrinoceros
Copy link
Contributor

(my rant about pytest-cov now has its own issue #330)

@neutrinoceros
Copy link
Contributor

neutrinoceros commented Nov 13, 2025

Phew, took me a while to get there, but I finally have something that works again: zacharyburnett#3

important notes: I couldn't, for the life of me, figure out where pytest-cov would write coverage data1, nor how it overwrites (as the documentation claims it does) coverage's --parallel-mode, so I had to resort to cutting the middle man again and invoke coverage directly. The obvious drawback is that users need to do the same thing (coverage run --parallel-mode -m pytest ...) from their tox.ini file to leverage this. But since it's a new feature, there's no backward incompatibility, so it should be acceptable, right ?

Footnotes

  1. to some extent, I suspect it might actively delete them

@neutrinoceros
Copy link
Contributor

neutrinoceros commented Nov 13, 2025

Oh and I just realized another important limitation : combining coverage data from different platforms is really tricky (TBH, I could never quite figure it out, but I did fiddle with this a couple times and the author claims it's possible). To the extent I understand how it's supposed to work, it should be possible to configure it on the user side.

If we're going to release this in its current state, it should be advertised very clearly.

@neutrinoceros
Copy link
Contributor

Whoops. Guess why I didn't run pre-commit hooks locally ? (a clue: #328)

@neutrinoceros
Copy link
Contributor

Also, there's a job stuck because it's trying to use macos-12, which isn't available anymore. This is already fixed on main though.

@neutrinoceros
Copy link
Contributor

@Cadair how should we proceed to get CI green again ?

@Cadair
Copy link
Member

Cadair commented Jan 26, 2026

pre-commit.ci autofix

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch 2 times, most recently from f36c9ff to 0ccd85e Compare February 24, 2026 14:51
@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch 4 times, most recently from 0130578 to cb41ea2 Compare February 25, 2026 18:58
Co-authored-by: Stuart Mumford <[email protected]>
Co-authored-by: Clément Robert <[email protected]>
@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch 2 times, most recently from 328d7b7 to 8829089 Compare February 25, 2026 19:07
@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Feb 25, 2026

Also added an additional change that uses uv to manage the Python installation in the coverage combination step, which appears to work fine in the tests:
image

@Cadair
Copy link
Member

Cadair commented Feb 25, 2026

Don't suppose you can move that uv commit to the uv PR? I think I'm happy to merge this otherwise?

@zacharyburnett
Copy link
Contributor Author

Don't suppose you can move that uv commit to the uv PR? I think I'm happy to merge this otherwise?

sure!

@zacharyburnett zacharyburnett force-pushed the tox/coverage_github_actions branch from 8829089 to be98dd6 Compare February 25, 2026 20:50
@Cadair Cadair merged commit a15a6d2 into OpenAstronomy:main Feb 25, 2026
138 checks passed
@Cadair
Copy link
Member

Cadair commented Feb 25, 2026

Thanks everyone!

- name: generate coverage report
run: |
python -Im pip install 'pip>=25.1'
python -Im pip install --group covcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait I just noticed this properly. This means that all the users of these workflows will need this in their package right? That seems bad (and undocumented) why wouldn't we just install coverage here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that all the users of these workflows will need this in their package right?

No, in this case this is checked out and installed from THIS repository using the covcheck group in pyproject.toml:

[dependency-groups]
concurrency = [
{include-group = "test"},
"pytest-repeat>=0.9.3",
"pytest-run-parallel>=0.4.4",
]
covcheck = [
"coverage[toml] ; python_version < '3.11'",
"coverage>=7.11.3",
"pytest-cov>=7.0.0",
]
test = [
"hypothesis>=6.113.0",
"pytest>=8.3.5",
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for doing code coverage reporting entirely on GitHub

4 participants